import http from "@/utils/http";
import { getToken, getUid } from "@/utils/token";

// 封装了首页的商品列表请求
export function regAPI(loginname, pwd) {
  // http.get()返回是一个promsie对象，promsie对象 记录异步操作（ajax请求）什么时候成功和失败
  // let promise = http.get("/api/pro/list", {
  //   params: { count: pageNum, limitNum: pageSize },
  // });
  // return promise;

  return http({
    method: "POST",
    url: "/api/user/reg",
    data: {
      loginname,
      password: pwd,
    },
  });
}
export function loginAPI(loginname, pwd) {
  // http.get()返回是一个promsie对象，promsie对象 记录异步操作（ajax请求）什么时候成功和失败
  // let promise = http.get("/api/pro/list", {
  //   params: { count: pageNum, limitNum: pageSize },
  // });
  // return promise;

  return http({
    method: "POST",
    url: "/api/user/login",
    data: {
      loginname,
      password: pwd,
    },
  });
}

export function getUserInfoAPI() {
  let userid = getUid();
  let token = getToken();
  return http({
    method: "GET",
    url: "/api/user/info",
    // data: {
    //   userid,
    // },
    params: { userid },
    headers: {
      token,
    },
  });
}

export function bindUserAvatarAPI(avatar) {
  let userid = getUid();
  let token = getToken();
  return http({
    method: "GET",
    url: "/api/user/binduseravatar",
    // data: {
    //   userid,
    // },
    params: { userid, avatar },
    headers: {
      token,
    },
  });
}
